//
//  ShareView.m
//  TYAlertControllerDemo
//
//  Created by tanyang on 15/10/26.
//  Copyright © 2015年 tanyang. All rights reserved.
//

#import "ShareView.h"
#import "UIView+TYAlertView.h"

@implementation ShareView
@synthesize surveyLinks;

- (IBAction)cancleAction:(id)sender {
    // hide view,or dismiss controller
    [self hideView];
}

- (IBAction)shareAction:(id)sender {
    // hide view,or dismiss controller
    UIButton *btn = (UIButton *)sender;
    NSInteger index = btn.tag;
    //分享到朋友圈
    [UMSocialConfig setFinishToastIsHidden:NO position:UMSocialiToastPositionCenter];
    
    UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:@"http://7xnkba.com1.z0.glb.clouddn.com/nps/563afb83c7f6975ab8a9f4fb/1447122722.9"];
    
    [UMSocialConfig setFinishToastIsHidden:NO position:UMSocialiToastPositionCenter];
    
    switch (index) {
        case 3: // @"微信"
        {
            [UMSocialData defaultData].extConfig.wechatSessionData.url = self.surveyLinks;
            
            [UMSocialData defaultData].extConfig.wechatSessionData.title = @"餐厅满意度调查";
            [UMSocialData defaultData].extConfig.wechatSessionData.shareText = @"感谢您在本餐厅用餐，请完成以下问卷，以便我们更好地为您服务";
            [UMSocialData defaultData].extConfig.wechatSessionData.urlResource = urlResource;
            break;
        }
        case 4:// @"朋友圈"
        {
           [UMSocialData defaultData].extConfig.wechatTimelineData.title = self.surveyLinks;
            [UMSocialData defaultData].extConfig.wechatTimelineData.urlResource = urlResource;
            break;
        }
        case 0:// @"新浪"
        {
            //[UMSocialData defaultData].extConfig.sinaData.urlResource = urlResource;
            [UMSocialData defaultData].extConfig.sinaData.shareText = self.surveyLinks;
            break;
        }
        case 1:// @"QQ"
        {
            [UMSocialData defaultData].extConfig.qqData.url = @"";
            
            [UMSocialData defaultData].extConfig.qqData.title = @"";
            [UMSocialData defaultData].extConfig.qqData.shareText = self.surveyLinks;
            //[UMSocialData defaultData].extConfig.qqData.urlResource = urlResource;
            break;
        }
        case 2:// @"短信"
        {
            [UMSocialData defaultData].extConfig.smsData.shareText = self.surveyLinks;
            //[UMSocialData defaultData].extConfig.smsData.urlResource = urlResource;
            break;
        }
        case 5:
        {
            //UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
            //pasteboard.string = self.surveyLinks;
        }
        default:
            break;
    }
    
    @try{
        [UMSocialSnsPlatformManager getSocialPlatformWithName:self.umSocialPlatformArray[index]].snsClickHandler(self.viewController,[UMSocialControllerService defaultControllerService],YES);
    }
    @catch(NSException *exception) {
        NSLog(@"exception:%@", exception);
    }
    @finally {
        
    }
    
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(NSArray *)umSocialPlatformArray{
    return @[UMShareToSina,UMShareToQQ, UMShareToSms,UMShareToWechatSession,    //微信好友
             UMShareToWechatTimeline,   //微信朋友圈
                         //新浪
           ];             //短信
}

//复制
- (IBAction)copy:(id)sender
{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.surveyLinks;
    [Config showMessage:@"复制成功"];
    [self hideView];
}
@end
